<?php
require './library/db_constants.php';
require './library/planets.php';
require './library/terrain.php';
require './library/deposits.php';

$planets = new planets;
$terrain = new terrain;
$deposit = new deposits;

$planetCount = $planets->planetCount();

if(isset($_POST['submit'])) {
    $deposit->createDeposit($_POST['deposit_name'], $_POST['deposit_size'], 
            $_POST['planets'], $_POST['coordinates'], $_POST['depositType']);
}


?>
<!DOCTYPE html>
<html charset="UTF-8">
    <head>
        <title>SWC Prospecting Manager || Create Deposit</title>
        <link rel="stylesheet" href="./library/css/createDeposit.css" />
        <script>
            function showMap(select) {
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        document.getElementById("map_wrapper").innerHTML=xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET","getmap.php?q="+select,true);
                xmlhttp.send();
            }
        </script>
    </head>
    <body>
        <h1>Create Deposit</h1>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
            <fieldset>
                <legend>Create Deposit</legend>
                
                <label for="deposit_name">Deposit Name: </label>
                <input type="text" name="deposit_name" placeholder="Deposit Name"
                       size="30" maxlength="80" class="createDeposit" />
                <br />
                <label for="deposite_size">Deposit Size: </label>
                <input type="text" name="deposit_size" placeholder="Deposit Size"
                       size="30" maxlength="80" class="createDeposit" />
                <br />
                <label for="planets">Planets: </label>
                <select name="planets" onclick="showMap(this.value);"
                        onchange="showMap(this.value);">
                    <?php
                        $x = 0;
                        $getPlanets = $planets->getPlanets();
                        while($x < $planetCount) {
                            echo "<option value='".$getPlanets[$x]['name']."'>
                                ".$getPlanets[$x]['name']."</option>";
                            $x++;
                        }
                    ?>
                </select>
                <div id="map_wrapper">

                </div>             
                    
                <div id="depositPanel">
                    <label for="depositType">Deposit Type: </label>
                    <select name="depositType">
                        <option value="Quantum">Quantum</option>
                        <option value="Meleenium">Meleenium </option>
                        <option value="Ardanium">Ardanium</option>
                        <option value="Rudic">Rudic</option>
                        <option value="Ryll">Ryll</option>
                        <option value="Duracrete">Duracrete</option>
                        <option value="Alazhi">Alazhi</option>
                        <option value="Laboi">Laboi</option>
                        <option value="Adegan">Adegan</option>
                        <option value="Rockivory">Rockivory</option>
                        <option value="Tibannagas">Tibannagas</option>
                        <option value="Nova">Nova</option>
                        <option value="Varium">Varium</option>
                        <option value="Varmigio">Varmigio</option>
                        <option value="Lommite">Lommite</option>
                        <option value="Hibridium">Hibridium</option>
                        <option value="Durelium">Durelium</option>
                        <option value="Lowickan">Lowickan</option>
                        <option value="Vertex">Vertex</option>
                        <option value="Berubian">Berubian</option>
                        <option value="Bacta">Bacta</option>
                    </select>
                    <br />
                    <input type="submit" value="Submit" name="submit" />
                </div>
            </fieldset>
        </form>
            <footer>
                <a href="index.php">Home</a> || <a href="createPlanet.php">Create Planets</a> ||
                <a href="listPlanets.php">List/Edit Planets</a> || <a href="listDeposits.php">List/Edit Deposits</a>
            </footer>
        
    </body>
</html>